<?php

namespace App\Repositories;

use App\User\Favors;

class FavorsRepositories
{
    public function list()
    {
        return Favors::with('questions')->where('userid', request()->user()->id)->get();
    }

    public function save($request)
    {
        $result = Favors::where('userid', $request->user()->id)->where('question', $request->question)->exists();
        $favors = new Favors;
        $favors->userid = $request->user()->id;
        $favors->question = $request->question;
        $favors->section = $request->section;
        return $result ? '0' : $favors->save();
    }

}
